/**
 * 
 */
package org.jackysoft.struts2.admin;

import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.HTMLTemplate;
import org.jackysoft.opensymphony.workflow.entity.WorkflowName;
import org.jackysoft.service.HTMLTemplateService;
import org.jackysoft.struts2.workflow.AbstractWorkflowAction;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;


/**
 * @author qujiakang
 * 
 */

@Namespace("/admin/form")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class FormManagerAction extends AbstractWorkflowAction<HTMLTemplate> {

	/**
	 * 
	 */
	private HTMLTemplateService service;
	private static final long serialVersionUID = -8329850868457632858L;
	private HTMLTemplate bean;
	private Collection<HTMLTemplate> beans;
	private WorkflowName name;

	


	@Override
	public String add() throws Exception {
		service.create(upLoad, upLoadFileName);
		return SUCCESS;
	}

	@Override
	public String update() throws Exception {
		service.update(bean, upLoad, upLoadFileName);
		return SUCCESS;
	}
	
	
	public String update2() throws Exception{
		service.update(bean.getId(), bean.getContent());
		return SUCCESS;
	}

	
	public String preview() throws Exception {
		bean = service.get(bean.getId());
		return "preview";
	}

	public HTMLTemplate getBean() {
		return bean;
	}

	public void setBean(HTMLTemplate bean) {
		this.bean = bean;
	}

	public Collection<HTMLTemplate> getBeans() {
		return beans;
	}

	public void setBeans(Collection<HTMLTemplate> beans) {
		this.beans = beans;
	}

	@Resource
	public void setService(HTMLTemplateService service) {
		this.service = service;
		this.setDataProvider(service);
	}

	public void setName(WorkflowName name) {
		this.name = name;
	}

	public WorkflowName getName() {
		return name;
	}

	public HTMLTemplateService getService() {
		return service;
	}

}